package com.darrenchan.leetcode;

/**
 * @Desc
 * @Author chenchi03
 * @CreateTime 2019-12-25 15:06
 */
public class QLint384 {
    public int lengthOfLongestSubstring(String s) {
        if(s == null || s.length() == 0) {
            return 0;
        }

        int i = 0;
        int res = 0;

        int[] chars = new int[256];
        for (int j = 0; j < s.length(); j++) {
            chars[s.charAt(j)]++;
            while (chars[s.charAt(j)] > 1) {
                chars[s.charAt(i)]--;
                i++;
            }
            res = Math.max(res, j - i + 1);
        }

        return res;
    }
}
